package com.rundatop.wx.service.impl;

import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.rundatop.dao.mapper.BaseGoodsMapper;
import com.rundatop.dao.mapper.BasePhoneMapper;
import com.rundatop.dao.model.BaseGoods;
import com.rundatop.dao.model.BasePhone;
import com.rundatop.wx.service.BasePhoneService;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
* 通用 Mapper 代码生成器
*
* @author mapper-generator
*/
@Service
public class BasePhoneServiceImpl extends BaseService<BasePhone> implements BasePhoneService{
	
	@Resource
    private BasePhoneMapper mapper;
	@Resource
	private BaseGoodsMapper goodsMapper;

    @Override
	public List<BasePhone> selectByBrandId(String brandId) {
		Example example = new Example(BasePhone.class);
        Criteria c = example.createCriteria();
//        c.andNotEqualTo("hidden", 1);
        if (brandId != null) {
            c.andEqualTo("brandId", brandId);
        }
        example.setOrderByClause(" sort_no asc ");
        return mapper.selectByExample(example);
	}

	@Override
	public List<BasePhone> getPhoneAndGoods(String brandId) {
		List<BasePhone> list = selectByBrandId(brandId);
		for (BasePhone basePhone : list) {
			List<BaseGoods> goods = goodsMapper.selectByPhoneId(basePhone.getId(), null);
			if (goods != null && goods.size() > 0) {
				basePhone.setChildren(goods);
			}
		}
		return list;
	}

}




